<template>
  <div>
    <cfg-pointer
      :mark="mark"
      v-model="editValue"
      :config="{type:'display'}"
      :label="label"
      :tip="tip"
      :disabled="disabled"
      :addField="addField"
      :clearable="true"
      :submitObj="submitObj"
      @clear="clear"
      @select="select"
    />
    <Modal
      v-model="drawer.show"
      :title="title || curTitle"
      v-bind="modalConfig"
      @on-ok="ok"
    >
      <div v-if="drawer.show" class="body-content">
        <component :is="isInstance ? 'Instance' : 'Model'" class="container-pointer-model"
            :type="type"
            :prefix="prefix"
            :searchData="editValue"
            :isPointer="true"
            @handleDbClick="handleDbClick"
            @handleSelect="handleSelect"
            @handleSelectCancel="handleSelectCancel"
            @nodeSelect="nodeSelect"
        />
      </div>
    </Modal>
  </div>
</template>

<script>
import Model from "../../../../configuration/src/pages/containerModelDesign/parts/model";
import Instance from "../../../../configuration/src/pages/containerModelDesign/parts/instance";
import pointerMixin from '../mixins/pointerMixin';

let titleObj ={
  logic: {"en-US": 'select logic model', "zh-CN": '选择逻辑模型'},
  staticLogic: {"en-US": 'select staticLogic model', "zh-CN": '选择静态逻辑模型'},
  statistics: {"en-US": 'select statistics model', "zh-CN": '选择报表模型'},
  tank: {"en-US": 'select tank model', "zh-CN": '选择箱体模型'},
  twins: {"en-US": 'select twins model', "zh-CN": '选择孪生模型'},
  routing: {"en-US": 'select routing model', "zh-CN": '选择工艺路线模型'},
  workCenter: {"en-US": 'select workCenter model', "zh-CN": '选择工作中心模型'},
  default: {"en-US": 'container model', "zh-CN": '选择模型'}
}
export default {
  name: "cfg-container-pointer",
  mixins: [pointerMixin],
  components: {Model, Instance},
  data() {
    return {
    }
  },
  methods: {
    nodeSelect(row) {
      console.log("file: cfgContainerPointer.vue:52  nodeSelect", row)
      this.rowData = row
      this.submit()
      this.drawer.show = false
    }
  },
  props:{
    disabled: {
      return: false
    },
    title: {
      default:()=>{
        return '';
      }
    },
    isInstance: {
      default:()=>{
        return false;
      }
    },
    // 选择数据后，需要回填的默认值，如 { linkModel: 'routing' }
    defaultObj: {
      default() {
        return {
          linkModel: ''
        }
      }
    },
    // 选择模型后，需要返回的数据字段
    submitObj: {
      default() {
        return {
          linkType: 'type',
          linkClassName: 'className',
          instanceId: '',
          nodeId: '',
        }
      }
    },
  },
  mounted() {
  },
  computed: {
    curTitle() {
      return (this.type && titleObj[this.type] ? titleObj[this.type] : titleObj.default)[this.G_Locale]
    },
  }
}
</script>

<style lang="less" scoped>
  .container-pointer-model /deep/ .cli-content-outline {
    height: auto;
  }
</style>